<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // function* fn() {
      //   console.log(1)
      //   console.log(2)
      //   console.log(3)

      //   return 'end'
      // }

      // fn()

      function* fn() {
        yield new Promise((resolve, reject) => {
          Math.floor(Math.random() * 100) > 50
            ? resolve('成功')
            : reject('失败')
        })
        console.log('hello')
        yield 2
        yield 3
        return 'end'
      }

      const f = fn()

      console.log(
        f.next().value.then(res => {
          console.log(res)
        })
      )
      // console.log(f.next())
      // console.log(f.next())
      // console.log(f.next())
    </script>
  </body>
</html>
